<?php

namespace app\shop\job;

use sheep\exception\SheepException;
use sheep\job\BaseJob;
use think\queue\Job;
use sheep\facade\Uploader;

/**
 * 设计师模板图片转存
 */
class Designer extends BaseJob
{

    /**
     * 转存
     */
    public function redeposit(Job $job, $data)
    {
        // 删除 job
        $job->delete();

        try {
            $imageList = $data['imageList'];
            foreach ($imageList as $image) {
                try {
                    Uploader::redeposit($image, parse_url($image, PHP_URL_PATH));
                } catch (SheepException $e) {
                    \think\facade\Log::error('设计师模板图片转存失败: ' . $e->getMessage());
                }
            }
        } catch (\Exception $e) {
            // 队列执行失败
            format_log_error($e, 'Designer.redeposit', '设计师模板图片转存队列');
        }
    }
}